package com.lamda.zhekou.vo;

import com.lamda.zhekou.model.UserVps;
import com.lamda.zhekou.utils.DateHelper;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by MJiao on 15/8/28.
 */
public class UserVpsVo {

    public static List<UserVpsVo> fromUserVpsList(List<UserVps> userVpsList) {
        List<UserVpsVo> userVpsVoList = new ArrayList<>();
        for (UserVps userVps : userVpsList) {
            UserVpsVo userVpsVo = new UserVpsVo();
            userVpsVo.setUserVpsId(userVps.getId());
            userVpsVo.setEmail(userVps.getUser().getEmail());
            userVpsVo.setIp(userVps.getVps().getIp());
            userVpsVo.setOs(userVps.getVps().getOs());
            userVpsVo.setVpsId(userVps.getVps().getId());
            userVpsVo.setVpsName(userVps.getVps().getVmName());
            userVpsVo.setStatus(userVps.getVps().getStatus());
            userVpsVo.setRmb(String.valueOf(userVps.getRmb()));
            userVpsVo.setStatusLastRefreshTime(userVps.getVps().getStatusLastRefreshTime());
            userVpsVo.setVmId(userVps.getVps().getVmId());
            userVpsVo.setComputerName(userVps.getVps().getComputerName());
            userVpsVo.setVpsId(userVps.getVps().getId());
            //购买天数
            int buyDay = DateHelper.daysBetween(new Date(userVps.getCreateTime().getTime()), new Date(userVps.getExpireTime().getTime()));
            userVpsVo.setBuyDays(String.valueOf(buyDay));
            //用string表示剩余时间
            String remailDateToString = DateHelper.remainDateToString(new Date(System.currentTimeMillis()), new Date(userVps.getExpireTime().getTime()));
            userVpsVo.setLeftTime(remailDateToString);
            //剩余天数
            int leftDay = DateHelper.daysBetween(new Date(System.currentTimeMillis()), new Date(userVps.getExpireTime().getTime()));
            /**
             * 1:  剩余时间大于7天->绿色
             * 2:  剩余时间小于7天->黄色
             * 3:  剩余时间小于3天->红色
             */
            if (leftDay < 0 || userVps.getExpireTime().getTime() < System.currentTimeMillis()) {
                userVpsVo.setWarningtStatus("red");
            } else if (leftDay <= 7) {
                userVpsVo.setWarningtStatus("yellow");
            } else {
                userVpsVo.setWarningtStatus("green");
            }
            userVpsVoList.add(userVpsVo);
        }
        return userVpsVoList;
    }

    private Long userVpsId;
    private Long vpsId;

    private String vmId;

    private String computerName;

    private String uptime;

    private String vpsName;

    /**
     * 状态(开启 ，关机)
     */
    private String status;

    /**
     * 备注
     */
    private String remark;
    /**
     * vps的ip
     */
    private String ip;

    /**
     * 状态的最后刷新时间
     */
    private Timestamp statusLastRefreshTime;

    /**
     * 操作系统
     */
    private String os;

    /**
     * 购买人
     */
    private String email;

    /**
     * 到期时间
     */
    private Timestamp expireTime;

    /**
     * 购买天数
     */
    private String buyDays = "--";

    private String rmb = "--";
    ;

    /**
     * 剩余时间
     */
    private int leftDays;

    /**
     * 剩余时间
     */
    private String leftTime;

    /**
     * 1:  剩余时间大于7天->绿色
     * 2:  剩余时间小于7天->黄色
     * 3:  剩余时间小于3天->红色
     */
    private String warningtStatus;

    public Long getVpsId() {
        return vpsId;
    }

    public void setVpsId(Long vpsId) {
        this.vpsId = vpsId;
    }

    public String getVpsName() {
        return vpsName;
    }

    public void setVpsName(String vpsName) {
        this.vpsName = vpsName;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Timestamp getStatusLastRefreshTime() {
        return statusLastRefreshTime;
    }

    public void setStatusLastRefreshTime(Timestamp statusLastRefreshTime) {
        this.statusLastRefreshTime = statusLastRefreshTime;
    }

    public String getWarningtStatus() {
        return warningtStatus;
    }

    public String getOs() {
        return os;
    }

    public void setOs(String os) {
        this.os = os;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Timestamp getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Timestamp expireTime) {
        this.expireTime = expireTime;
    }

    public String getBuyDays() {
        return buyDays;
    }

    public void setBuyDays(String buyDays) {
        this.buyDays = buyDays;
    }

    public String getRmb() {
        return rmb;
    }

    public void setRmb(String rmb) {
        this.rmb = rmb;
    }

    public int getLeftDays() {
        return leftDays;
    }

    public void setLeftDays(int leftDays) {
        this.leftDays = leftDays;
    }

    public String getLeftTime() {
        return leftTime;
    }

    public void setLeftTime(String leftTime) {
        this.leftTime = leftTime;
    }

    public String String() {
        return warningtStatus;
    }

    public void setWarningtStatus(String warningtStatus) {
        this.warningtStatus = warningtStatus;
    }

    public String getVmId() {
        return vmId;
    }

    public void setVmId(String vmId) {
        this.vmId = vmId;
    }

    public String getComputerName() {
        return computerName;
    }

    public void setComputerName(String computerName) {
        this.computerName = computerName;
    }

    public String getUptime() {
        return uptime;
    }

    public void setUptime(String uptime) {
        this.uptime = uptime;
    }

    public Long getUserVpsId() {
        return userVpsId;
    }

    public void setUserVpsId(Long userVpsId) {
        this.userVpsId = userVpsId;
    }

    @Override
    public String toString() {
        return "UserVpsVo{" +
                "userVpsId=" + userVpsId +
                ", vpsId=" + vpsId +
                ", vmId='" + vmId + '\'' +
                ", computerName='" + computerName + '\'' +
                ", uptime='" + uptime + '\'' +
                ", vpsName='" + vpsName + '\'' +
                ", status='" + status + '\'' +
                ", remark='" + remark + '\'' +
                ", ip='" + ip + '\'' +
                ", statusLastRefreshTime=" + statusLastRefreshTime +
                ", os='" + os + '\'' +
                ", email='" + email + '\'' +
                ", expireTime=" + expireTime +
                ", buyDays='" + buyDays + '\'' +
                ", rmb='" + rmb + '\'' +
                ", leftDays=" + leftDays +
                ", leftTime='" + leftTime + '\'' +
                ", warningtStatus=" + warningtStatus +
                '}';
    }
}
